package com.niuquan.activitie;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Spinner;

import com.niuquan.adapter.SpinnerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DELL on 2015/5/23.
 */
public class FindExpertFragment extends Fragment {
    Spinner city;
    Spinner province;
    Spinner zhiye;
    Spinner shanchang;
    Spinner rank;
    String choosedcity;
    String choosedprovince;
    String choosedzhiye;
    String choosedshanchang;
    String choosedrank;
    List<String> provincelist;
    List<String> citylist;
    List<String> zhiyelist;
    List<String> shanchanglist;
    List<String> ranklist;
    SpinnerAdapter provinceadapter;
    SpinnerAdapter cityadapter;
    SpinnerAdapter zhiyeadapter;
    SpinnerAdapter shanchangadapter;
    SpinnerAdapter rankadapter;
    ImageButton mohusou;
    ImageButton jingquesou;
    LinearLayout mohuchaxunlayout;
    ScrollView jingquesouview;
    LinearLayout xueshenglayout;
    RelativeLayout xueshengcontrol;
    ImageButton sousuobutton;
    ImageButton sousuobutton1;
    boolean state;
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        return inflater.inflate(R.layout.layout_xunniu, container, false);
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        state = false;
        super.onActivityCreated(savedInstanceState);
        province = (Spinner)getView().findViewById(R.id.shengspinner);
        city = (Spinner)getView().findViewById(R.id.shispinner);
        zhiye = (Spinner)getView().findViewById(R.id.zhiyespinner);
        shanchang = (Spinner)getView().findViewById(R.id.shanchangspinner);
        rank = (Spinner)getView().findViewById(R.id.rankspinner);
        mohusou = (ImageButton)getView().findViewById(R.id.mohuchaxunbutton);
        jingquesou = (ImageButton)getView().findViewById(R.id.jingquebutton);
        jingquesouview = (ScrollView)getView().findViewById(R.id.jingquechaxun);
        xueshenglayout = (LinearLayout)getView().findViewById(R.id.xuesheng);
        xueshengcontrol = (RelativeLayout)getView().findViewById(R.id.xueshenglayout);
        sousuobutton = (ImageButton)getView().findViewById(R.id.soushuobutton);
        mohuchaxunlayout = (LinearLayout)getView().findViewById(R.id.mohuchaxun);
        sousuobutton1 = (ImageButton)getView().findViewById(R.id.soushuobutton1);
        sousuobutton1.setSelected(true);
        province.setPrompt("省");
        city.setPrompt("市");
        zhiye.setPrompt("职业");
        shanchang.setPrompt("擅长领域");
        rank.setPrompt("星级");
         provincelist = new ArrayList<String>();
        citylist= new ArrayList<String>();
     zhiyelist= new ArrayList<String>();
         shanchanglist= new ArrayList<String>();
        ranklist= new ArrayList<String>();
        provincelist.add("浙江省");
        provincelist.add("四川省");
        citylist.add("杭州市");
        citylist.add("金华市");
        zhiyelist.add("IT");
        shanchanglist.add("C++");
        ranklist.add("1星以上");
        provinceadapter=  new SpinnerAdapter(getActivity(),provincelist);
        province.setAdapter(provinceadapter);
        cityadapter = new SpinnerAdapter(getActivity(),citylist);
        city.setAdapter(cityadapter);
        zhiyeadapter = new SpinnerAdapter(getActivity(),zhiyelist);
        zhiye.setAdapter(zhiyeadapter);
        shanchangadapter = new  SpinnerAdapter(getActivity(),shanchanglist);
        shanchang.setAdapter(shanchangadapter);
        rankadapter = new SpinnerAdapter(getActivity(),ranklist);
        rank.setAdapter(rankadapter);
        province.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                choosedprovince = (String) parent.getItemAtPosition(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        city.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                choosedcity = (String)parent.getItemAtPosition(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        zhiye.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                choosedzhiye = (String)parent.getItemAtPosition(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        shanchang.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                choosedshanchang = (String)parent.getItemAtPosition(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        rank.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                choosedrank = (String) parent.getItemAtPosition(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        mohusou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jingquesou.setSelected(false);
                mohusou.setSelected(true);
                jingquesouview.setVisibility(View.GONE);
                mohuchaxunlayout.setVisibility(View.VISIBLE);
                sousuobutton1.setVisibility(View.VISIBLE);
            }
        });
        jingquesou.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jingquesou.setSelected(true);
                mohusou.setSelected(false);
                jingquesouview.setVisibility(View.VISIBLE);
                sousuobutton1.setVisibility(View.GONE);
                mohuchaxunlayout.setVisibility(View.GONE);
            }
        });
        xueshengcontrol.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!state) {
                    xueshenglayout.setVisibility(View.VISIBLE);
                    state =true;
                } else {
                    xueshenglayout.setVisibility(View.GONE);
                    state = false;
                }
            }
        });
        sousuobutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        sousuobutton1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
}
